package main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

public class Statistics {
private int Budget;
private int Gained;
private int Spent;
private HashMap<String, Vector<Pack<Integer>>> equipmentPacks;
private HashMap<String, Vector<Pack<Lab>>> LabPacks;
private HashMap<String, Vector<Pack<Scientist>>> ScientistPacks;
private ArrayList<Expirement> finishedExperiments;

public Statistics(int initial_budget)
{
	Budget=initial_budget;
	equipmentPacks = new HashMap<String, Vector<Pack<Integer>>>(30);
	LabPacks = new HashMap<String, Vector<Pack<Lab>>>();
	ScientistPacks = new HashMap<String, Vector<Pack<Scientist>>>();
	finishedExperiments = new ArrayList<Expirement>();
}

public void addEquipmentPack(String name,Pack<Integer> pack)
{
	if(!equipmentPacks.containsKey(name))
		equipmentPacks.put(name, new Vector<Pack<Integer>>());
	equipmentPacks.get(name).add(new Pack<Integer>(new Integer(pack.getData()),pack.getPrice()));
	
}

public void addLabPack(String name,Pack<Lab> pack)
{
	if(!LabPacks.containsKey(name))
		LabPacks.put(name, new Vector<Pack<Lab>>());
	LabPacks.get(name).add(new Pack<Lab>(new Lab(pack.getData()),pack.getPrice()));
	
}

public void addScientistPack(String name,Pack<Scientist> pack)
{
	if(!ScientistPacks.containsKey(name))
		ScientistPacks.put(name, new Vector<Pack<Scientist>>());
	ScientistPacks.get(name).add(new Pack<Scientist>(new Scientist(pack.getData()),pack.getPrice()));
	
}

public void addFinishedExperiment(Expirement experiment)
{
	finishedExperiments.add(experiment);
}

@Override
public String toString() {
	StringBuilder ans = new StringBuilder("Budget: ");
	ans.append(Budget);
	ans.append("\nGained:");
	ans.append(Gained);
	ans.append("\nSpent:");
	ans.append(Spent);
	ans.append("\nLabs purchased:");
	
	Iterator<String> it =LabPacks.keySet().iterator();
	
	while(it.hasNext())
	{
		ans.append("\n\t");
		String spec = it.next();
		//ans.append(spec);
		//ans.append(":");
		ans.append(LabPacks.get(spec).toString());
	}
	
	ans.append("\nScientists purchased:");
	it = ScientistPacks.keySet().iterator();
	while(it.hasNext())
	{
		ans.append("\n\t");
		String spec = it.next();
		//ans.append(spec);
		//ans.append(":");
		ans.append(ScientistPacks.get(spec).toString());
	}
	ans.append("\nEquipment purchased:");
	it=equipmentPacks.keySet().iterator();
	while(it.hasNext())
	{
		ans.append("\n\t");
		String eq = it.next();
		ans.append(eq);
		ans.append(" amount:");
		ans.append(equipmentPacks.get(eq).toString());
	}
	
	ans.append("\nExperiments Completed:");
	Iterator<Expirement> itExp=finishedExperiments.iterator();
	while(itExp.hasNext())
	{
		ans.append("\n\t");
		Expirement exp = itExp.next();
		ans.append(exp.toString());
	}
	
	return ans.toString();
}

public int getBudget() {
		return Budget;
	}
public void useBudget(int amount)
{
	Budget=Budget-amount;
	Spent=Spent+amount;
}
public void addBudget(int amount)
{
	Budget=Budget+amount;
	Gained=Gained+amount;
	
}
public void updateSimulationTime(long startTime, long endTime) {
	// TODO Auto-generated method stub
	
}

}
